package leetcode.median;

/**
 * ClassName: $74_SearchMatrix
 * Description:
 * date: 2022-02-19 9:32
 *
 * @author liyifan
 */
public class $74_SearchMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length;
        int col = matrix[0].length;
        if (row == 0 || col == 0) return false;

        int i = row - 1;
        int j = 0;
        while (i >= 0 && j < col) {
            if (matrix[i][j] == target) {
                return true;
            } else if(matrix[i][j] < target){
                // 向右搜索
                j++;
            } else {
                i--;
            }
        }
        return false;
    }
}
